package com.mfin.bs.mgr.impl;

import com.mfin.bom.factory.CustomerInformationFactory;
import com.mfin.bom.factory.FinanceInformationFactory;
import com.mfin.bom.factory.FinanceLoanInformationFactory;
import com.mfin.bom.factory.LoanMasterFactory;
import com.mfin.bom.factory.UserInformationFactory;
import com.mfin.bom.factory.interfaces.ICustomerInformationFactory;
import com.mfin.bom.factory.interfaces.IFinanceInformationFactory;
import com.mfin.bom.factory.interfaces.IFinanceLoanInformationFactory;
import com.mfin.bom.factory.interfaces.ILoanMasterFactory;
import com.mfin.bom.factory.interfaces.IUserInformationFactory;
import com.mfin.bom.interfaces.ICashbook;
import com.mfin.bom.interfaces.ICustomer;
import com.mfin.bom.interfaces.IFinance;
import com.mfin.bom.interfaces.IFinanceLoan;
import com.mfin.bom.interfaces.IPartner;
import com.mfin.bom.interfaces.IUser;
import com.mfin.bs.mgr.interfaces.ICashBookManager;
import com.mfin.vo.CashbookVO;
import com.mfin.vo.CustomerVO;
import com.mfin.vo.PartnerVO;
import com.mfin.vo.UserVO;
import com.mfin.vo.finance.FinanceVO;
import com.mfin.vo.loan.FinanceLoanVO;

public class CashBookManager extends BaseManager implements ICashBookManager {

	ICustomerInformationFactory customerInformationFactory = new CustomerInformationFactory();
	IFinanceInformationFactory financeInformationFactory = new FinanceInformationFactory();
	IUserInformationFactory userInformationFactory = new UserInformationFactory();
	ILoanMasterFactory loanMasterFactory = new LoanMasterFactory();
	IFinanceLoanInformationFactory financeLoanInformationFactory = new FinanceLoanInformationFactory();
	

	@Override
	public CashbookVO addEntry(FinanceVO financeVO, CashbookVO cashbookVO) {
		logMethodBegin("CashBookManager", "addEntry");
		
		financeInformationFactory.setPersistenceGovernor(getPersistenceGovernor());
		customerInformationFactory.setPersistenceGovernor(getPersistenceGovernor());
		userInformationFactory.setPersistenceGovernor(getPersistenceGovernor());
		financeLoanInformationFactory.setPersistenceGovernor(getPersistenceGovernor());
		
		CustomerVO customerVO = cashbookVO.getCustomer();
		PartnerVO partnerVO = cashbookVO.getPartner();
		FinanceLoanVO financeLoanVO=cashbookVO.getFinanceLoan();
		UserVO userVO = cashbookVO.getUser();

		ICashbook bomCashBook = financeInformationFactory.createCashBookEntry(financeVO);
		
		IFinance bomFinanceInformation = financeInformationFactory.getFinanceInformation(financeVO);
		IFinanceLoan bomFinanceLoan = financeLoanInformationFactory.getLoan(financeLoanVO);
		ICustomer bomCustomer = customerInformationFactory.getCustomerInformation(customerVO);
		IPartner bomPartner = customerInformationFactory.getPartnerInformation(partnerVO);
		IUser bomUser = userInformationFactory.getUserInformation(userVO);

		map(cashbookVO, bomCashBook, false, false);
		
		bomCashBook.setUser(bomUser);
		bomCashBook.setCustomer(bomCustomer);
		bomCashBook.setFinance(bomFinanceInformation);
		bomCashBook.setFinanceLoan(bomFinanceLoan);
		bomCashBook.setPartner(bomPartner);

		map(bomCashBook, cashbookVO, false, true);
		
		logMethodEnd("CashBookManager", "addEntry");
		return cashbookVO;
	}
}
